<?php

/**
 * Joomla! Full Page Background Plugin
 *
 * @package		Joomla.Plugin
 * @subpackage	System.fullpagebackground
 *
 * 	Copyright (C) 2011  Brian Tyndall - http://www.webdogz.co.uk
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// no direct access
defined('_JEXEC') or die;

function randomImage($array) {
	$total = count($array);
	$call = rand(0,$total-1);
	return $array[$call];
}

function listImages($path, $restrictSize, $minWidth, $minHeight) {
	$images = glob($path . "*.jpg");	 
	$imageFiles = Array();
	$tempImage = '';
	foreach($images as $image)
	{
		//Add in functionality for definable file types later
		list($width, $height, $type, $attr) = getimagesize($image);
		if($restrictSize == 1 && $width < (int)$minWidth && $height < (int)$minWidth) {
		} else {
			$tempImage = explode(JPATH_BASE, $image);
			array_push($imageFiles, $tempImage);
		}
	}
	return $imageFiles;
}

function checkEmptyDirectory($folder) {
		if (! is_dir($folder))
			return false;
	
		$files = opendir($folder);
		while ($file = readdir($files)) {
			if ($file != '.' && $file != '..')
			return true;
		} 	
}

function assignImage($image, $centerImage) {
		ob_start();
		?>
		jQuery(document).ready(function() {
		$('<div id="supersized"></div>').prependTo('body');
		$.fn.supersized.options = {  
			startwidth: 640,  
			startheight: 480,
			vertical_center: <?php echo $centerImage; ?>,
			slides : [
				{image : '<?php echo $image; ?>' }
			]
		};
		$('#supersized').supersized(); 
		});

		<?php
		return ob_get_clean();
}

function fixPath($path) {
	if(substr($path, -1) != DS) {
		$path = $path . DS;
	}
	return $path;
	
}

function parseObjectToArray($object) {
    $array = array();
    if (is_object($object)) {
        $array = get_object_vars($object);
    }
    return $array;
}	
	
?>